/**
 * 
 */
package com.misoo.ex06;

import java.util.ArrayList;
import java.util.Map;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * @author daniel.chai
 * 
 */
public class ex06 extends Activity {
	private ListView lv;
	private TextView tv;
	private DataModel dm;
	private ArrayList<Map<String, Object>> coll;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		dm = new DataModel();
		setContentView(R.layout.list);
		lv = (ListView) findViewById(R.id.list);
		lv.setOnItemClickListener(listener);

		tv = (TextView) findViewById(R.id.text);
		coll = dm.loadData();

		SimpleAdapter adapter = new SimpleAdapter(this, coll,
				android.R.layout.simple_list_item_1,
				new String[] { "prod_na" }, new int[] { android.R.id.text1 });
		lv.setAdapter(adapter);
	}

	OnItemClickListener listener = new OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			tv.setTextColor(Color.RED);
			tv.setText(coll.get(arg2).get("prod_type").toString());
		};
	};
}
